home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c-part1 / 3805 < prev    next >
Encoding:
Internet Message Format  |  1996-08-05  |  1.3 KB

  1. Path: gryphon.phoenix.net!usenet
  2. From: brucew@phoenix.net (Bruce Wedding)
  3. Newsgroups: comp.lang.c
  4. Subject: Re: Problem with arrays
  5. Date: Wed, 31 Jan 1996 07:13:27 GMT
  6. Organization: BranPaul Systems
  7. Message-ID: <4en2ig$6af@gryphon.phoenix.net>
  8. References: <4ejtia$6id@sifon.cc.mcgill.ca>
  9. NNTP-Posting-Host: dial73.phoenix.net
  10. X-Newsreader: Moe's Newsreader    
  11.  
  12.  
  13. >typedef struct nodebox NODEBOX, *TRIE
  14. >
  15. >struct nodebox{
  16. >{    int letters[100];
  17. >    TRIE subtree[100];
  18. >};
  19. > But here's the problem: before inserting any letter in the trie, I expect the
  20. >elements in the array letters to be all zeros( '\0' ) like in a normal empty
  21. >array. But instead, the elements of this arrays are weird numbers like 
  22. >25678. It bothers me since I assume that they are '\0' in my insert function. 
  23.  
  24. C does not explicitly initialize arrays unless they are defined
  25. global.  You will have to zero out the array.  You can use a loop
  26. or the memset function.  I think the loop is a little safer,
  27. though maybe not as fast.
  28.  
  29. NODEBOX test;
  30. int i = 0;
  31.  
  32. for (; i < sizeof(test.letters)/sizeof(test.letters[0]); i++)
  33.   test.letters[i] = 0;
  34.  
  35.  
  36. Bruce D. Wedding                        Have Compiler, Will Travel!
  37.               Perspicacious Programming Performed Promptly
  38. Katy, Texas, USA, Planet Earth, Milkyway Galaxy, Known Universe
  39.  
  40.